<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>3D Snake Game</title>
    <style>
        @import url('https://fonts.googleapis.com/css2?family=Noto+Sans+SC:wght@400;700&display=swap');

        body {
            display: flex;
            flex-direction: column;
            align-items: center;
            justify-content: center;
            min-height: 100vh;
            margin: 0;
            background-color: #1a1b1e;
            font-family: 'Noto Sans SC', Arial, sans-serif;
            overflow: hidden;
            color: #ffffff;
        }

        #game-container {
            position: relative;
            width: 100vw;
            height: 100vh;
        }

        canvas {
            width: 100%;
            height: 100%;
        }

        .dialog {
            display: none;
            position: absolute;
            top: 50%;
            left: 50%;
            transform: translate(-50%, -50%);
            text-align: center;
            background: linear-gradient(145deg, #e31837, #ff0000);
            padding: 20px 30px;
            border-radius: 20px;
            box-shadow: 0 10px 25px rgba(0,0,0,0.3);
            color: white;
            opacity: 0;
            transition: all 0.3s ease;
            max-height: 80vh;
            overflow-y: auto;
            z-index: 1000;
        }
        .dialog.active {
            display: block;
            opacity: 1;
            transform: translate(-50%, -50%) scale(1);
        }

        .dialog h1 {
            font-size: 36px;
            margin: 0 0 20px 0;
            text-shadow: 2px 2px 4px rgba(0,0,0,0.3);
        }

        .dialog h2 {
            font-size: 28px;
            margin: 0 0 15px 0;
            text-shadow: 2px 2px 4px rgba(0,0,0,0.3);
        }

        .dialog p {
            font-size: 18px;
            margin: 10px 0;
            line-height: 1.5;
        }

        .dialog .stats {
            background: rgba(255,255,255,0.1);
            border-radius: 15px;
            padding: 15px;
            margin: 20px 0;
        }

        button {
            background: #ffffff;
            color: #e31837;
            border: none;
            border-radius: 30px;
            padding: 12px 30px;
            font-size: 18px;
            font-weight: bold;
            cursor: pointer;
            margin: 10px;
            transition: all 0.2s ease;
            font-family: 'Noto Sans SC', Arial, sans-serif;
            text-transform: uppercase;
            letter-spacing: 1px;
            box-shadow: 0 4px 15px rgba(0,0,0,0.2);
        }

        button:hover {
            transform: translateY(-2px);
            box-shadow: 0 6px 20px rgba(0,0,0,0.3);
            background: #f8f8f8;
        }

        button:active {
            transform: translateY(1px);
        }
        #language-btn {
            position: absolute;
            top: 20px;
            right: 20px;
            z-index: 1000;
            background: rgba(255,255,255,0.1);
            color: #ffffff;
            border: none;
            border-radius: 15px;
            padding: 10px 20px;
            font-size: 16px;
            font-weight: bold;
            cursor: pointer;
            backdrop-filter: blur(5px);
            transition: all 0.2s ease;
        }

        #language-btn:hover {
            background: rgba(255,255,255,0.2);
            transform: translateY(-2px);
        }

        #language-btn:active {
            transform: translateY(1px);
        }
        #score {
            position: absolute;
            top: 20px;
            left: 20px;
            font-size: 24px;
            font-weight: bold;
            background: rgba(255,255,255,0.1);
            padding: 10px 20px;
            border-radius: 15px;
            backdrop-filter: blur(5px);
        }

        .controls {
            margin: 20px 0;
            font-size: 16px;
            color: rgba(255,255,255,0.9);
        }

        .highlight {
            color: #FFD700;
            font-weight: bold;
        }

        /* 任天堂风格操控盘样式 */
        #controls {
            position: absolute;
            bottom: 100px;
            left: 50%;
            transform: translateX(-50%);
            display: grid;
            grid-template-areas:
                ". up ."
                "left . right"
                ". down .";
            gap: 10px;
            background: rgba(255, 255, 255, 0.1);
            padding: 20px;
            border-radius: 20px;
            backdrop-filter: blur(5px);
            z-index: 999;
        }
        .control-btn {
            background: linear-gradient(145deg, #ffffff, #e6e6e6);
            color: #1a1b1e;
            border: none;
            border-radius: 12px;
            width: 50px;
            height: 50px;
            font-size: 20px;
            cursor: pointer;
            transition: all 0.2s;
            box-shadow: -2px -2px 5px rgba(255, 255, 255, 0.1),
                       2px 2px 5px rgba(0, 0, 0, 0.3);
            display: flex;
            align-items: center;
            justify-content: center;
            font-weight: bold;
        }

        #up { grid-area: up; }
        #left { grid-area: left; }
        #right { grid-area: right; }
        #down { grid-area: down; }

        .control-btn:hover {
            background: linear-gradient(145deg, #f0f0f0, #ffffff);
            transform: translateY(-2px);
            box-shadow: -3px -3px 7px rgba(255, 255, 255, 0.2),
                       3px 3px 7px rgba(0, 0, 0, 0.4);
        }

        .control-btn:active {
            background: linear-gradient(145deg, #e6e6e6, #ffffff);
            transform: translateY(1px);
            box-shadow: -1px -1px 3px rgba(255, 255, 255, 0.1),
                       1px 1px 3px rgba(0, 0, 0, 0.2);
        }
    </style>
</head>
<body>
    <div id="game-container">
        <button id="language-btn" onclick="switchLanguage()" class="language-btn">Language: 中文</button>
        <div id="score">Score: 0</div>
        
        <div id="welcome" class="dialog active">
            <h1>3D Snake Game</h1>
            <p>Welcome to this challenging 3D world!</p>
            <div class="controls">
                Use <span class="highlight">↑←↓→</span> or <span class="highlight">WASD</span> to control direction
            </div>
            <p>Each time you eat food, the scene will rotate, bringing new challenges!</p>
            <button onclick="startGame()">Start Game</button>
        </div>

        <div id="game-over" class="dialog">
            <h2>Game Over</h2>
            <div class="stats">
                <p><span id="final-score-label">Final Score: </span><span id="final-score" class="highlight">0</span></p>
                <p><span id="final-rank-label">Global Rank: </span><span id="final-rank" class="highlight">Calculating...</span></p>
                <p class="rank-note" style="font-size: 14px; color: rgba(255,255,255,0.7);">全球排名系统即将上线</p>
            </div>
            <button onclick="startGame()">Play Again</button>
        </div>

        <div id="controls" class="controls">
            <button class="control-btn" id="up">↑</button>
            <button class="control-btn" id="left">←</button>
            <button class="control-btn" id="right">→</button>
            <button class="control-btn" id="down">↓</button>
        </div>
    </div>
    <script src="https://cdnjs.cloudflare.com/ajax/libs/three.js/r128/three.min.js"></script>
    <script src="https://cdnjs.cloudflare.com/ajax/libs/tween.js/18.6.4/tween.umd.js"></script>
    <script src="i18n.js"></script>
    <script src="game3d.js"></script>
</body>
</html>